package com.phonemica.utils;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;

import org.json.JSONArray;
import org.json.JSONException;

public class Constant {

	public static final int BASE = 0;

	public static final int IMG_COUNT = 36;

	public static final String SAVE_PATH = "/sdcard/games/";

	public static final String SHESHIDU = "\u2103";

	public static final String EXTRA = "EXTRA";
	public static final String SEARCH_RESULT = "SEARCH_RESULT";
	public static final String PROGRESS = "PROGRESS";
	public static final String STATE = "STATE";
	public static final String EXTRA_FILE_SIZE = "EXTRA_FILE_SIZE";
	public static final String EXTRA_DOWN_SIZE = "EXTRA_DOWN_SIZE";

	public static class Config {
		public final static int DEFAULT_WIDTH = 1136;
		public final static int DEFAULT_HEIGHT = 640;
		public static int DISPLAY_WIDTH;// 854
		public static int DISPLAY_HEIGHT;// 480
		public static float DISPLAY_DENSITY;
		public static int DISPLAY_DENSITYDPI;
		public static float DISPLAY_WIDTH_RATION;
		public static float DISPLAY_HEIGHT_RATION;
	}

	public static class Net {
		public static final String BASE = "http://phonemica.net/";
		public static final String SEARCH_SALE_LOCATION = BASE
				+ "/api/mobile/searchsalelocation.php";
		public static final String SEARCH_SALE = BASE
				+ "/api/mobile/searchsale.php";
		public static final String RESERVATION = BASE
				+ "/api/mobile/reservation.php";
	}

	public static class ADDRESS {
		private static JSONArray addressStr;
		private static Map<Integer, String> provinceMap = new HashMap<Integer, String>();

		public static void setValue(String value) {
			if (null != addressStr) {
				return;
			}
			try {
				addressStr = new JSONArray(value);
				if (null != addressStr) {
					JSONArray jarray = null;
					for (int i = 0; i < addressStr.length(); i++) {
						jarray = addressStr.getJSONArray(i);
						if (0 == jarray.getInt(1))// ʡ
						{
							provinceMap.put(Integer.valueOf(jarray.getInt(0)),
									jarray.getString(2));
						}
					}
					jarray = null;
				}
			} catch (JSONException e) {
				e.printStackTrace();
			}
		}

		public static Map<Integer, String> getCities(int pid) {
			Map<Integer, String> theResult = new HashMap<Integer, String>();
			if (null != addressStr) {
				JSONArray jarray = null;
				for (int i = 0; i < addressStr.length(); i++) {
					try {
						jarray = addressStr.getJSONArray(i);
						if (pid == jarray.getInt(1))// ʡ
						{
							theResult.put(Integer.valueOf(jarray.getInt(0)),
									jarray.getString(2));
						}
					} catch (JSONException e) {
						e.printStackTrace();
					}
				}
				jarray = null;
			}
			return theResult;
		}

		public static Map<Integer, String> getCities(String pname) {
			if (null != provinceMap) {
				Iterator<Entry<Integer, String>> iter = provinceMap.entrySet()
						.iterator();
				while (null != iter && iter.hasNext()) {
					Entry<Integer, String> entry = iter.next();
					if (pname.equals(entry.getValue())) {
						return getCities(entry.getKey());
					}
				}
			}
			return null;
		}

		public static Map<Integer, String> getProvinces() {
			return provinceMap;
		}
	}

	public static class DIR {
		// public static final String WEATHER = "/data/data/"
		// + HavalApp.self.getPackageName() + "/weather/";
		// public static final String BASE = "/data/data/" +
		// HavalApp.self.getPackageName() + File.separator;

		public static final String BASE = "/sdcard/games/";
	}

	public static class ACTION {
		public static final String WEATHER = "com.haval.weather";
		public static final String UPDATE_DOWNLOAD = "UPDATE_DOWNLOAD";
		public static final String DOWNLOAD = "DOWNLOAD";
		public static final String STOP_DOWNLOAD = "STOP_DOWNLOAD";
		public static final String DOWNLOAD_ERROR = "DOWNLOAD_ERROR";
	}

	public static class JSON {
		public static final String ID = "id";
		public static final String IMG = "img";
		public static final String TITLE = "title";
		public static final String NAME = "name";
		public static final String AGE = "age";
		public static final String SEX = "sex";
		public static final String INFO = "info";
		public static final String COLOR = "color";
		public static final String YANSE = "yanse";
		public static final String CAMPAIGN = "campaign";
		public static final String S1 = "s1";
		public static final String CITY = "city";
		public static final String LOCATION = "location";
		public static final String FY = "fy";
		public static final String FY2 = "fy2";
		public static final String FANGYAN = "fangyan";
		public static final String PIAN = "pian";
		public static final String XIAOPIAN = "xiaopian";
		public static final String X = "x";
		public static final String Y = "y";
		public static final String COUNTRY = "country";
		public static final String PROVINCE = "province";
		public static final String LENGTH = "length";
		public static final String START = "start";
		public static final String STOP = "stop";
		public static final String B = "b";
		public static final String H = "h";
		public static final String I = "i";
		public static final String P = "p";
		public static final String E = "e";
		
		public static final String CLASS = "class";
	}

}
